#!/bin/bash

echo "===================================="
echo "   数据一致性验证工具"
echo "===================================="
echo ""

DB_USER="root"
DB_PASS="123456"
DB_NAME="sanguosha"

# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR" || exit 1

echo "[步骤1] 检查数据库连接..."
mysql -u "$DB_USER" -p"$DB_PASS" -e "SELECT VERSION();" > /dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "[错误] 无法连接数据库，请检查MySQL是否运行"
    echo ""
    exit 1
fi
echo "[成功] 数据库连接正常"
echo ""

echo "[步骤2] 验证武将数据..."
mysql -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" < sql/verify_images.sql
echo ""

echo "[步骤3] 检查图片文件..."
echo ""
echo "图片目录内容："
ls -1 img/*.{jpg,jpeg,png} 2>/dev/null | xargs -n 1 basename
echo ""

echo "[完成] 验证完成！"
echo ""
echo "提示："
echo "1. 检查上面输出的'问题类型'列，应该没有错误"
echo "2. 确认图片文件名与数据库记录一致"
echo "3. 如有问题，请参考'数据管理指南.md'"
echo ""
